<?php

/**
 * 分类标签
 * Some rights reserved：rfcsite.com
 * Contact email:458481812@qq.com
 */
namespace Home\TagLib;

class Cate {

    public $db, $table_name, $modelid, $where;



    /**
     * 子栏目
     * @param $catid
     */
    public function son($data) {

    	$cache=(int)$data[cache];
    	$catid = ( int ) $data ['catid'];

    	$num=$data ['num']?$data ['num']:20;
    	$limit = $data ['limiet']?$data ['limiet']:0;
    	$model = $data ['model'];

    if ($catid)		{
    		$where ['parentid'] = array (	"EQ",	$catid 		);
    	}	else{
    		$where ['parentid'] = array (	"EQ",	'0' 		);

    	}
    	if ($model)			$where ['model'] = array (	"EQ",	$model 		);

    	$where ['status'] = array (	"EQ",1 	);

    	if (isset($data['where']) && $data['where']) {
    		$where['_string'] = $data['where'];
    	}
    	$order = empty ( $data ['order'] ) ? "listorder DESC,id desc" : $data ['order'];

    	if($cache){
    		$result = M ( "Cate" )->field('content',true)->cache(true,$cache)->where ( $where )->limit ( $num )->order ( $order )->select ();

    	}
    	else{
    		$result = M ( "Cate" )->field('content',true)->where ( $where )->limit ( $limit,$num )->order ( $order )->select ();
    	}

   // 	echo M()->getLastSql();

    	return $result;



    }

    /**
     * 兄弟栏目
     * @param $catid
     */
    public function self($data) {

    	$cache=(int)$data[cache];

    	$cates=F("Cates");
    	$catid=$cates[( int ) $data ['catid']][parentid];

    	$num=$data ['num']?$data ['num']:20;
    	$limit = $data ['limiet']?$data ['limiet']:0;
    	$model = $data ['model'];

    	if ($catid)		{
    		$where ['parentid'] = array (	"EQ",	$catid 		);
    	}	else{
    		$where ['parentid'] = array (	"EQ",	'0' 		);

    	}
    	if ($model)			$where ['model'] = array (	"EQ",	$model 		);

    	$where ['status'] = array (	"EQ",1 	);

    	if (isset($data['where']) && $data['where']) {
    		$where['_string'] = $data['where'];
    	}
    	$order = empty ( $data ['order'] ) ? "listorder DESC,id desc" : $data ['order'];

    	if($cache){
    		$result = M ( "Cate" )->field('content',true)->cache(true,$cache)->where ( $where )->limit ( $num )->order ( $order )->select ();

    	}
    	else{
    		$result = M ( "Cate" )->field('content',true)->where ( $where )->limit ( $limit,$num )->order ( $order )->select ();
    	}



    	return $result;



    }


    public function tree($data){


    	if($data ['ismenu']){

    	$result = M ( "Cate" )->field('content',true)->order("listorder DESC,id DESC")->where(array("status"=>"1","ismenu"=>'1'))->select();

    	}else{

    	if($data ['catid']){

    		$result=F("Cates_tree_".$data["catid"]);
    	}else{
    		$result=F("Cates_tree");
    	}
    	}

    	//print_r($result);

    	return $result;

    }

    public function one($data){
    	$cat=F("Cates")[$data[catid]];
    	return $cat;


    }
    public function breadcrumb($data){
    	$cates=F("Cates");
    	$arrparentid=$cates[( int ) $data ['catid']][arrparentid];

    	$cats=explode ( ",", $arrparentid );

    	$result[]=array(
    		"id"=>0,
    			"url"=>C("SITE_URL"),
    			"name"=>"主页",

    	);
    	foreach ($cats as $key=>$v){
    		$result[]=$cates[$v];

    	}
    	return $result;

    }


    public function more($data){



    	$cache=(int)$data[cache];
    	$catid = $data ['catid'];

    	$num=$data ['num']?$data ['num']:20;
    	$limit = $data ['limiet']?$data ['limiet']:0;
    	$model = $data ['model'];

    	$where ['id'] = array (	"IN",	$catid 		);
    	if ($model)			$where ['model'] = array (	"EQ",	$model 		);

    	$where ['status'] = array (	"EQ",1 	);

    	if (isset($data['where']) && $data['where']) {
    		$where['_string'] = $data['where'];
    	}
    	$order = empty ( $data ['order'] ) ? "listorder DESC,id desc" : $data ['order'];

    	if($cache){
    		$result = M ( "Cate" )->field('content',true)->cache(true,$cache)->where ( $where )->limit ( $num )->order ( $order )->select ();

    	}
    	else{
    		$result = M ( "Cate" )->field('content',true)->where ( $where )->limit ( $limit,$num )->order ( $order )->select ();
    	}

    	// 	echo M()->getLastSql();

    	return $result;




    }


}
